package com.fks.fks_service.mapper;

import com.fks.fks_service.pojo.CategoryDB;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface CategoryMapper {

    @Select("select * from fks_category where isDelete='0' and displayOrder!='0' order by level,displayOrder")
    List<CategoryDB> getCategory();

    @Insert("insert into fks_category (categoryName1,categoryName2,categoryName3,picture,level,belongId,createTime,isDelete,createMerchantUserId,displayOrder)" +
            "values(#{categoryName1},#{categoryName2},#{categoryName3},#{picture},#{level},#{belongId},#{createTime},#{isDelete},#{createUserId},#{displayOrder})")
    int addCategory(CategoryDB categoryDB);

    @Update("update fks_category set updateUserId=#{updateUserId},categoryName1=#{categoryName1}" +
            ",categoryName2=#{categoryName2},categoryName3=#{categoryName3}" +
            ",picture=#{picture},level=#{level},belongId=#{belongId}" +
            ",isDelete=#{isDelete},updateTime=#{updateTime},displayOrder=#{displayOrder} where id=#{id}")
    int updateCategory(CategoryDB categoryDB);

    @Select("select * from fks_category where id=#{id}")
    CategoryDB getCategoryById(int id);

    @Select("select * from fks_category where isDelete='0' and level=#{level}" +
            " order by displayOrder,createTime limit #{page},#{pageSize}")
    List<CategoryDB> getCategoryByLevel(String level, int page, int pageSize);

    @Update("update into fks_category set isDelete='1' where belongId=#{id}")
    int deleteCategoryByBelongId(int id);

    @Select("select id from fks_category where belongId=#{id}")
    List<Integer> getCategoryByBelongId(int id);

    @Select("select * from fks_category where belongId=#{id} and isDelete='0'")
    List<CategoryDB> getCategoryDBByBelongId(int id);

    @Select("select * from fks_category where belongId=#{categoryId} and isDelete='0'")
    List<CategoryDB> getCategoryList(String categoryId);
}
